//
//  DoneViewController.m
//  Hand shadow
//
//  Created by A-01 on 2020/7/21.
//  Copyright © 2020 A-01. All rights reserved.
//

#import "DoneViewController.h"

@interface DoneViewController ()

@property (nonatomic, weak)UIView * blueView;
@property (nonatomic, weak)UILabel * overLabel;
@property (nonatomic, weak)UILabel * scoreLabel;
@property (nonatomic, weak)UILabel * exploreLabel;
@property (nonatomic, strong)UIButton * backBtn;
@property (nonatomic, strong)UIButton * againButton;

@end

@implementation DoneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.backButton.hidden = YES;
    [self setupUI];
}


- (void)setupUI{
    
    UIView * blueView = [UIView new];
    
    blueView.backgroundColor = [UIColor colorWithHexString:@"BDE0F9"];
    blueView.layer.borderWidth = 1.5;
    blueView.layer.borderColor = [[UIColor colorWithHexString:@"66BDDD"] CGColor];
    blueView.layer.masksToBounds = YES;
    
    self.blueView = blueView;
    
    [self.view addSubview:self.blueView];

    
    UILabel * overLabel = [UILabel new];
    
    if ([self.type isEqualToString:@"done"]) {
        
        overLabel.text = @"Success";
    }else{
        
        overLabel.text = @"Game Over";
    }
    overLabel.textColor = [UIColor colorWithHexString:@"2C8FB4"];
    overLabel.font = [UIFont fontWithName:@"Chalkduster" size:25];
    overLabel.textAlignment = NSTextAlignmentCenter;
    
    self.overLabel = overLabel;
    
    [self.blueView addSubview:self.overLabel];
    
    
    UILabel * scoreLabel = [UILabel new];
    
    scoreLabel.text = [NSString stringWithFormat:@"Score: %d",self.score];
    scoreLabel.textColor = ZRBlackColor;
    scoreLabel.font = [UIFont boldSystemFontOfSize:18];
    scoreLabel.textAlignment = NSTextAlignmentCenter;
    
    self.scoreLabel = scoreLabel;
    
    [self.blueView addSubview:self.scoreLabel];
    
    
    UILabel * exploreLabel = [UILabel new];
    
    if ([self.type isEqualToString:@"done"]) {
        
        exploreLabel.text = @"";
    }else{
        
        exploreLabel.text = @"It’s a pity that the challenge has failed. \n Let’s work together";
    }
    exploreLabel.textColor = ZRBlackColor;
    exploreLabel.font = [UIFont boldSystemFontOfSize:16];
    exploreLabel.numberOfLines = 0;
    
    self.exploreLabel = exploreLabel;
    
    [self.blueView addSubview:self.exploreLabel];
    
    
    self.backBtn = [self setupButtonWithTitle:@"Back"];
    [self.blueView addSubview:self.backBtn];
    self.againButton = [self setupButtonWithTitle:@"Again"];
    [self.blueView addSubview:self.againButton];
}

- (void)clickButton:(UIButton *)button{
    
    if (button == self.backBtn) {
        
        [self.navigationController popToRootViewControllerAnimated:YES];
    }else{
        
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}

- (void)viewDidLayoutSubviews{
        
    [super viewDidLayoutSubviews];

    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.centerX.mas_equalTo(self.view);
        make.width.mas_equalTo(450);
        make.height.mas_equalTo(220);
    }];

    [self.overLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.blueView);
        make.top.mas_equalTo(self.blueView).offset(15);
    }];
    
    [self.scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(self.overLabel.mas_bottom).offset(5);
    }];
    
    [self.exploreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(self.scoreLabel.mas_bottom).offset(10);
        make.width.mas_equalTo(250);
    }];
    
    [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.view).offset(-kScreenW / 2 - 30);
        make.bottom.mas_equalTo(self.blueView).offset(-20);
        make.width.mas_equalTo(110);
        make.height.mas_equalTo(40);
    }];
    
    [self.againButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(kScreenW / 2 + 30);
        make.centerY.width.height.mas_equalTo(self.backBtn);
    }];
}

- (UIButton *)setupButtonWithTitle:(NSString *)title{
    
    UIButton * button = [UIButton new];
    
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:ZRWhiteColor forState:UIControlStateNormal];
    [button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    [button setBackgroundColor:[UIColor colorWithHexString:@"2C8FB4"]];
    button.titleLabel.font = [UIFont boldSystemFontOfSize:18];
    button.layer.cornerRadius = 20;
    button.layer.masksToBounds = YES;
        
    return button;
}

@end
